package utils;

import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

public class Util {

	public static String printIntArray(int[] indices){
		StringBuffer arrayString = new StringBuffer("{");
		for(int i = 0; i < indices.length - 1; i++)
			arrayString.append(indices[i] + ", ");
		arrayString.append(indices[indices.length - 1] + " }");
		return arrayString.toString();
	}	
	
	//get a list of all integers starting from zero up to n-1
	//used to limit the size of categories chosen from within an attribute class
	public static Integer[] getFirstNIntegers(int n){
		Integer[] result = new Integer[n];
		for(int i = 0; i < n; i++){
			result[i] = i;
		}
		return result;
	}
	
	//used to specify all sectors with one attribute set
	//all other indices will have a -1 in them
	public static int[] getIndexArrayWithOneValue(int size, int index, int value){
		int[] result = new int[size];
		for(int i = 0; i < size; i++){
			result[i] = -1;
		}
		result[index] = value;
		return result;
	}
	
	//used to specify all sectors with two attributes set
	//all other indices will have a -1 in them
	public static int[] getIndexArrayWithTwoValues(int size, int index1, int value1,
			int index2, int value2){
		int[] result = new int[size];
		for(int i = 0; i < size; i++){
			result[i] = -1;
		}
		result[index1] = value1;
		result[index2] = value2;
		return result;
	}	
	
	public static String printListOfIntegers(List<Integer> combination){
		StringBuffer combinationString = new StringBuffer("{");
		for(int i : combination){
			combinationString.append(i + ",");
			
		}
		int length = combinationString.length();
		if(length > 1)
			//combinationString.substring(0, length - 2);
			combinationString.deleteCharAt(length - 1);
		combinationString.append("}");
		//System.out.println(combinationString);
		return combinationString.toString();
	}	
	
	public static void printListOfListOfIntegers(List<List<Integer>> combinations){
		StringBuffer listString = new StringBuffer("{");
		for(List<Integer> list : combinations){
			listString.append(printListOfIntegers(list) + ";");
			//printListOfIntegers(list);
		}
		if(combinations.size() > 0) listString.deleteCharAt(listString.length() -1 );
		listString.append("}");
		System.out.println(listString.toString());
	}	
	
	public static <S,T> void printMap(Map<S,T> map){
		for(Entry<S, T> entry : map.entrySet()){
			System.out.print(entry.getKey() + "->" + entry.getValue() + ", ");
		}
		System.out.println("");
	}	
	
}
